package com.fkrl.newhr.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.fkrl.newhr.domain.Department;
import com.fkrl.newhr.dao.DepartmentDao;
import com.fkrl.newhr.util.CommonUtil;
import com.fkrl.newhr.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fkrl.newhr.util.constants.ErrorEnum;

import java.util.List;

/**
 * Created by Bruce on 2018/4/10.
 */
@Service
public class DepartmentServiceImpl implements DepartmentService {
    @Autowired
    private DepartmentDao departmentDao;

    /**
     * 获取公司列表
     *
     * @param jsonObject
     * @return
     */
    @Override
    public JSONObject listDepartment(JSONObject jsonObject) {
        CommonUtil.fillPageParam(jsonObject);
        int count = departmentDao.countDepartment(jsonObject);
        List<Department> list = departmentDao.listDepartment(jsonObject);
        return CommonUtil.successPage(jsonObject, list, count);
    }

    /**
     * 新增公司
     *
     * @param
     * @return
     */
    @Override
    public JSONObject addDepartment(Department department) {
        int exist = departmentDao.queryExistDepartmentname(department);
        if (exist > 0) {
            return CommonUtil.errorJson(ErrorEnum.E_10009);
        }
        int ret= departmentDao.insert(department);
        return CommonUtil.successJson(ret);
    }

    /**
     * 更新公司
     *
     * @param
     * @return
     */
    @Override
    public JSONObject updateDepartment(Department department) {
        departmentDao.updateByPrimaryKeySelective(department);
        return CommonUtil.successJson();
    }

}
